package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.cart.client.CartFeignClient;
import com.atguigu.gmall.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * 加入购物车
 */
@Controller
public class CartController {

    @Autowired
    private CartFeignClient cartFeignClient;

    //加入购物车
    @GetMapping("addCart.html")
    public String addCart(Long skuId, Integer skuNum, Model model){

        //1:加入商品到购物车中
        Result result = cartFeignClient.addCart(skuId, skuNum);
        //2:返回值 就购物车
        model.addAttribute("cartInfo",result.getData());//CartInfo
        //3转发视图
        return "cart/addCart";
    }
    //去购物车页面
    @GetMapping("/cart.html")
    public String toCart(){
        return "cart/index";
    }
}
